<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    
    <title>My JSP 'loginAction.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <jsp:useBean id="login" class="dao.LoginDao"></jsp:useBean>
    <%String username=request.getParameter("username");
    	//将username转码为 utf-8中文编码
    	if(null!=username&&!"".equals(username))username=new String(username.getBytes("iso-8859-1"),"utf-8");
    	String password=request.getParameter("password");
    	String role=request.getParameter("role");
    	//将role转换为整形量存储于r变量
    	int r=0;
    	if(null!=role&&!"".equals(role)){r=Integer.parseInt(role);}
     	String result=login.login(username,password,r);
     	if(result.equals("managerSuccess")){
     		session.setAttribute("uname",username);
     		response.sendRedirect("studentManage/stuAdmin.jsp");
     	}else if(result.equals("teacherSuccess")){
     		session.setAttribute("uname",username);
     		response.sendRedirect("teacherEntry/teaEntry.jsp");
     	}else if(result.equals("studentSuccess")){
     		session.setAttribute("uname",username);
     		response.sendRedirect("studentEntry/stuEntry.jsp");
     	}else{
    %>
    	<script type="text/javascript">
    		alert("用户名或密码错误！");
    		window.location.href="index.jsp";
    	</script>
    <% 		
     	}
     %>
  </body>
</html>
